﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using Lodop;
using System.IO;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream(@"C:\Users\Cloud\Desktop\Rp_报表_固定样式.html", FileMode.OpenOrCreate, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF8);
            string s = sr.ReadToEnd();
            string s2 = RemoveSpaceBetweenTags(s);
            sr.Close();
            fs.Close();


            Lodop.LodopXClass MyLodop = new Lodop.LodopXClass();
            //打印内容
            MyLodop.ADD_PRINT_HTM(0, 0, "210mm", "10000mm", s2);
            MyLodop.SET_PRINT_PAGESIZE(3, "210mm", "5mm", "");

            //MyLodop.ADD_PRINT_HTM(0, 0, "100%", "BottomMargin:-2mm", s2);
            //for (int i = 0; i < 2; i++)
            //{
            //MyLodop.ADD_PRINT_IMAGE(0, 0, 2100, 1800, @"D:\2.png");
            //MyLodop.SET_PRINT_STYLEA(0,"Stretch",2);//按原图比例(不变形)缩放模式
            //MyLodop.SET_PRINT_STYLEA(0, "Stretch", 1);//(可变形)扩展缩放模式

            //打印方式
            //MyLodop.SET_PRINT_PAGESIZE(1, 2100, 1500, ""); //纵向普通
            // MyLodop.SET_PRINT_PAGESIZE(3, 2100, 45, "");//高度自适应
            //MyLodop.SET_PRINT_MODE("POS_BASEON_PAPER", true);//输出以纸张边缘为基点

            MyLodop.SET_LICENSES("深圳市网通兴技术发展有限公司", "89B0F5A2F8858B1DCA112FB77A8104F2", "", "");
            // MyLodop.PRINT();
            MyLodop.PREVIEW();
            //}
        }

        public string RemoveSpaceBetweenTags(string html)
        {
            html = Regex.Replace(html, @">\s+\r", ">");
            html = Regex.Replace(html, @">\s+\n", ">");
            html = Regex.Replace(html, @">\s+<", "><");

            return html;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream(@"C:\Users\Cloud\Desktop\Rp_报表_固定样式.html", FileMode.OpenOrCreate, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF8);
            string s = sr.ReadToEnd();
            string s2 = RemoveSpaceBetweenTags(s);
            sr.Close();
            fs.Close();


            Lodop.LodopXClass MyLodop = new Lodop.LodopXClass();
            //打印内容
            MyLodop.ADD_PRINT_HTM(0, 0, "210mm", "10000mm", s2);
            MyLodop.SET_PRINT_PAGESIZE(3, "210mm", "5mm", "");
            MyLodop.SET_LICENSES("深圳市网通兴技术发展有限公司", "89B0F5A2F8858B1DCA112FB77A8104F2", "", "");
            MyLodop.PRINT();

        }
    }
}
